<template>
  <div class="Row_content" style="width:965px;" id="market_freegift_create">
    <Form
        inline
        ref="formValidate"
        :model="formValidate"
        :rules="ruleValidate"
        :label-width="130">
        <FormItem label="活动名称:" prop="activityName">
          <Input v-model="formValidate.activityName" placeholder="请输入" class='input-wid' :maxlength="20" @on-keyup='filterName' @on-blur="filterName"></Input>
        </FormItem>
        <FormItem></FormItem>
        <FormItem label="开始时间:" prop="activityStart">
          <DatePicker :value="formValidate.activityStart" type="datetime" :editable="false" placeholder="请选择" style="width: 280px" @on-change="activityStartChange" :options="activityStartOptions"></DatePicker>
        </FormItem>
        <FormItem label="结束时间:" prop="activityEnd">
          <DatePicker :value="formValidate.activityEnd" type="datetime" :editable="false" placeholder="请选择" style="width: 280px" @on-change="activityEndChange" :options="activityEndOptions"></DatePicker>
        </FormItem>
        <FormItem label="面向会员:" prop="faceMember">
          <Select v-model="formValidate.faceMember" multiple :max-tag-count='4' :max-tag-placeholder='maxTagPlaceholder'>
            <Option v-for="(item, index) in memberLevelList" :value="item.memberLevel" :key="index">{{'V' + item.memberLevel}}</Option>
          </Select>
        </FormItem>
        <FormItem label="面向门店:" prop="faceShop">
          <treeselect class="treeselect_box" placeholder="请选择"
              :options="options" style="width:280px;"
              v-model='formValidate.faceShop' multiple value-consists-of="LEAF_PRIORITY"
              :normalizer="normalizer" :limitText='limitText' :limit='1'
              />
        </FormItem>
        <FormItem label="营销渠道:" prop="channel">
          <Select v-model="formValidate.channel" multiple>
            <Option v-for="(item, index) in channelList" :value="item.value" :key="index">{{ item.label }}</Option>
          </Select>
        </FormItem>
        <FormItem label="适用产品:" prop="ableProduct">
          <Select v-model="formValidate.ableProduct" multiple @on-change='changeProduct'>
            <Option v-for="(item, index) in categoryList" :value="item.value"  :key="index">{{ item.label }}</Option>
          </Select>
        </FormItem>
        <div class="add-level" v-if="formValidate.addCouponGift.length>0" v-for="(item,idx) in formValidate.addCouponGift" :key='idx'>
          <div class="del-level"><Button type="primary" @click='delLevel(item, idx)'>删除本层级</Button></div>
          <Form :ref="`item${idx}`" :model="item" :rules="giftValidate[idx]" :label-width="130">
            <FormItem class='chunk' :label="activityTypeId === '6' ? '满赠活动:' : activityTypeId === '7' ?'满减活动:': activityTypeId === '8' ?'折扣活动:':'' " v-for="(ele,i) in item.values" :key='i'>
              <Row type='flex' style="width: 600px;">
                <Col>
                  <FormItem  class='level-special1' :rules="{required: true, trigger: 'change', validator: validatePass(idx, i)}" :prop="'values.' + i + '.value1'" >
                    <div style="display: flex;width: 400px;">
                      <p style="width: 65px;">{{ele.id === '3' ? '游戏币': ele.id === '4' ? '游戏券': ele.id === '5' ? '游戏卡' : ele.id === '6' ? '休闲项目': ele.id === '7' ? '小商品': ele.id === '22' ? 'SVIP会员' : ''}}</p>
                      <p style="width: 80px;"> —— 金额满</p>
                      <Input placeholder="请输入" style="width:96px" v-model='item.values[i].value1' :value='item.values[i].value1' :maxlength='5' @on-keyup="filterPrice(idx, i)" @on-blur="filterPrice(idx, i)"></Input>
                      <p style="margin-left: 5px">元</p>
                      <p style="width:60px;margin-left: 50px" v-if="activityTypeId === '6'">赠送礼包</p>
                    </div>
                  </FormItem>
                </Col>
                <Col v-if="activityTypeId === '7' || activityTypeId === '8'">
                  <FormItem class='level-special2' :prop="'values.' + i + '.value2'" :rules="{required: true, trigger: 'change', validator: validatePass2(idx, i)}">
                    <div style="display: flex;margin-left: 50px;width: 150px;">
                      <span style="margin-right: 5px;">{{activityTypeId === '7' ? '减' : '打'}}</span>
                      <Input placeholder="请输入" class='input- wid' style="width:96px" v-model='item.values[i].value2' :value='item.values[i].value2' :maxlength="activityTypeId === '7' ? 5 : activityTypeId === '8' ? 3 : ''" @on-keyup="filterRate(idx, i)" @on-blur="rateBlur(idx, i)"></Input>
                      <span style="margin-left: 5px;">{{activityTypeId === '7' ? '元' : '折'}}</span>
                    </div>
                  </FormItem>
                </Col>
              </Row>
            </FormItem>
            <FormItem label="赠送积分:" v-if="activityTypeId === '6'" prop='integral'>
              <Input placeholder="请输入" class='input-wid' style="width:260px" v-model='item.integral' :maxlength='9' @on-keyup="filterIntegral(idx)" @on-blur="filterIntegral(idx)"></Input>
            </FormItem>
            <FormItem label="选择优惠券:" v-if="activityTypeId === '6'" class='chunk' prop='couponList'>
              <select-coupon v-model="item.couponList" @addcoupon="addcoupon(item, idx)"></select-coupon>
            </FormItem>
          </Form>
        </div>
        <FormItem label="" class='chunk' prop="addRankNum" v-if="formValidate.ableProduct.length>0">
          <Button @click='addGiftNum'>新增一级礼包 +</Button><span style="margin-left:10px;color: #808695;width:130px">最多可设置5个等级</span>
        </FormItem>
        <!-- <FormItem label="推送微信消息:" prop="sendWechat" v-if="activityTypeId === '6'">
          <Select v-model="formValidate.sendWechat" @on-change="selectWechatChange">
            <Option v-for="(item, index) in sendWechats"
                    :value="item.id"
                    :key="index">
              {{ item.templateName }}
            </Option>
          </Select>
        </FormItem> -->
        <FormItem label="推送短信消息:" prop="sendMessage" v-if="activityTypeId === '6'">
          <Select v-model="formValidate.sendMessage" @on-change="selectMessageChange">
            <Option v-for="(item, index) in sendMessages"
                    :value="item.id"
                    :key="index">
              {{ item.templateName }}
            </Option>
          </Select>
        </FormItem>
        <!-- <FormItem label="微信消息模板:" style="width: 830px" v-show="formValidate.sendWechat !== '-1' && activityTypeId === '6'">
          <Input
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 8 }"
            style="width:700px" disabled v-model="wechat"></Input>
        </FormItem> -->
        <FormItem label="短信消息模板:" style="width: 830px" v-show="formValidate.sendMessage !== '-1' && activityTypeId === '6'">
          <Input
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 8 }"
            style="width:700px" disabled v-model="message"></Input>
        </FormItem>
        <FormItem label="活动说明:" prop="activityRemark" class='chunk'>
          <Input v-model="formValidate.activityRemark" style="width:700px"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 8 }"
            :maxlength="200"
            placeholder="请输入"></Input>
            <div style="text-align:right;width:700px;color:#c5c8ce;">{{formValidate.activityRemark.length}}/200</div>
        </FormItem>
        <FormItem class="form-btn" style="margin-top: 5px;">
        <Button type="primary" class="system-submit-btn" @click="handleSubmit">确定</Button>
        <Button class="system-submit-btn" style="margin-left: 8px" @click='handleReset'>取消</Button>
      </FormItem>
    </Form>
    <drawer-coupon v-model="Dmodal" :data="activityGiftList" :maxsize='20' :origin='1' @sure="handleSelectCoupon"></drawer-coupon>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import enumsMixin from '../enums.js'
import { routeEqual } from '@/libs/util'
import { addFreeGift } from '@/api/market/freegift.js'
import { getMemberLevelList } from '@/api/member/index'
import SelectCoupon from '@/view/components/select-coupon/index.vue'
import DrawerCoupon from '@/view/components/drawer-coupon/index.vue'
import { getMessages } from '@/api/market/message'
import { getEmployeeTree } from '@/api/system/employee.js'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
  name: 'market_freegift_create',
  mixins: [enumsMixin],
  components: { SelectCoupon, DrawerCoupon, Treeselect },
  computed: {
    ...mapState({
      merchantId: state => state.user.merchantId,
      userId: state => state.user.userId,
      userName: state => state.user.userName
    })
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      if (vm.activityTypeId !== to.params.type) {
        vm.activityTypeId = to.params.type
        vm.$refs.formValidate.resetFields()
        vm.giftValidate = []
      }
    })
  },
  watch: {
    'formValidate.ableProduct' (val) {
      if (val.length > 0) {
      } else {
        this.formValidate.addRankNum = 0
        this.formValidate.addCouponGift = []
      }
    },
    Dmodal (status) {
      if (!status) {
        this.activityGiftList = []
      }
    }
  },
  data () {
    return {
      options: [],
      normalizer (node) {
        if (node.childList) {
          if (node.childList.length > 0) {
            return {
              id: node.id,
              label: node.orgName,
              children: node.childList
            }
          } else {
            return {
              id: node.id,
              label: node.orgName
            }
          }
        }
      },
      itemIdx: '',
      giftValidate: [],
      activityTypeId: '',
      memberLevelList: [], // 会员等级列表
      Dmodal: false,
      submitLock: false,
      addId: '',
      activityGiftList: [],
      wechat: '',
      message: '',
      sendWechats: [{ templateName: '无', id: '-1' }],
      sendMessages: [{ templateName: '无', id: '-1' }],
      formValidate: {
        activityName: '',
        activityStart: '',
        activityEnd: '',
        faceMember: [],
        faceShop: [],
        channel: [],
        ableProduct: [],
        sendWechat: '-1',
        sendMessage: '-1',
        activityRemark: '',
        addRankNum: 0,
        addCouponGift: []
      },
      ruleValidate: {
        sendWechat: { required: true, message: '请选择是否发送微信消息' },
        sendMessage: { required: true, message: '请选择是否发送短信消息' },
        activityName: { required: true, message: '请填写活动名称', trigger: 'blur' },
        activityStart: {
          required: true,
          trigger: 'change',
          validator: (rule, value, callback) => {
            if (!new Date(this.formValidate.activityStart).getTime()) {
              callback(new Error('请选择开始时间'))
            } else if (new Date(this.formValidate.activityStart).getTime() > new Date(this.formValidate.activityEnd).getTime() || new Date(this.formValidate.activityStart).getTime() === new Date(this.formValidate.activityEnd).getTime()) {
              callback(new Error('开始时间要小于结束时间'))
            } else {
              callback()
            }
          }

        },
        activityEnd: {
          required: true,
          trigger: 'change',
          validator: (rule, value, callback) => {
            if (!new Date(this.formValidate.activityEnd).getTime()) {
              callback(new Error('请选择结束时间'))
            } else if (new Date(this.formValidate.activityStart).getTime() > new Date(this.formValidate.activityEnd).getTime() || new Date(this.formValidate.activityStart).getTime() === new Date(this.formValidate.activityEnd).getTime()) {
              callback(new Error('结束时间要大于开始时间'))
            } else if (new Date().getTime() > new Date(this.formValidate.activityEnd).getTime()) {
              callback(new Error('结束时间要大于当前系统时间'))
            } else {
              callback()
            }
          }
        },
        faceMember: { required: true, message: '请选择面向的会员', type: 'array', trigger: 'change' },
        faceShop: {
          required: true,
          message: '请选择面向的门店',
          trigger: 'change',
          type: 'array'
        },
        channel: { required: true, message: '请选择营销渠道', type: 'array', trigger: 'change' },
        ableProduct: { required: true, message: '请选择适用产品', type: 'array', trigger: 'change' },
        pushMsg: { required: true, message: '请选择推送微信消息' },
        addRankNum: [
          {
            required: true,
            type: 'number',
            validator: (rule, value, callback) => {
              if (this.formValidate.addCouponGift.length < 1) {
                callback(new Error('等级礼包未设置'))
              } else {
                callback()
              }
            }
          }
        ]
      },
      activityStartOptions: {},
      activityEndOptions: {}
    }
  },
  methods: {
    limitText () {
      return '...'
    },
    getOrgTree () { // 获取组织机构树
      getEmployeeTree({
        'merchantId': this.$store.state.user.merchantId,
        'status': 1,
        'orgType': 1
      }).then((res) => {
        if (res.data.status === 200) {
          this.options.push(res.data.data)
        } else {
          this.$Message.error(res.data.error)
        }
      })
    },
    validatePass2 (idx, i) {
      return (rule, value, callback) => {
        if (value === '') {
          if (this.activityTypeId === '7') {
            callback(new Error('请填写金额'))
          } else {
            callback(new Error('请填写折扣'))
          }
        } else {
          if (this.activityTypeId === '7') {
            let value1 = this.formValidate.addCouponGift[idx].values[i].value1
            let value2 = this.formValidate.addCouponGift[idx].values[i].value2
            if (value1) {
              if (value1 - value2 > 0) {
                callback()
              } else {
                callback(new Error('减额要小于满减额'))
              }
            } else {
              callback()
            }
          } else {
            callback()
          }
        }
      }
    },
    validatePass (idx, i) {
      return (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请填写金额'))
        } else {
          if (this.activityTypeId === '7') {
            let value1 = this.formValidate.addCouponGift[idx].values[i].value1
            let value2 = this.formValidate.addCouponGift[idx].values[i].value2
            if (value1 - value2 > 0) {
              callback()
            } else {
              callback(new Error('满减额要大于减额'))
            }
          } else {
            callback()
          }
        }
      }
    },
    getEnums (templateType) {
      return new Promise((resolve, reject) => {
        getMessages({
          templateType,
          merchantId: this.merchantId,
          suitableType: this.activityTypeId,
          status: 1
        }).then(res => {
          const result = res.data || {}
          if (result.status === 200) {
            resolve(result.data)
          } else {
            this.$Message.error(`${result.error}`)
          }
        }).catch(err => {
          this.$Message.error(`${err}`)
        })
      })
    },
    selectWechatChange (value) {
      this.formValidate.sendWechat = value
      if (value) {
        this.sendWechats.forEach(item => {
          if (item.id === value) {
            this.wechat = item.content
          }
        })
      } else {
        this.wechat = ''
      }
    },
    selectMessageChange (value) {
      this.formValidate.sendMessage = value
      if (value) {
        this.sendMessages.forEach(item => {
          if (item.id === value) {
            this.message = item.content
          }
        })
      } else {
        this.message = ''
      }
    },
    maxTagPlaceholder (num) {
      return '...'
    },
    filterName () {
      this.formValidate.activityName = this.formValidate.activityName.replace(/[^0-9A-Za-z\u4e00-\u9fa5]/, '')
    },
    filterIntegral (idx) {
      let val = this.formValidate.addCouponGift[idx].integral
      val = val.replace(/[^\d]/g, '')
      if (val.length > 1) {
        val = val.replace(/[^\d]/g, '').replace(/^0{1,}/g, '')
      }
      this.$set(this.formValidate.addCouponGift[idx], 'integral', val)
    },
    filterPrice (idx, i) {
      let val = this.formValidate.addCouponGift[idx].values[i].value1
      val = val.replace(/[^\d]/g, '').replace(/^0{1,}/g, '')
      this.$set(this.formValidate.addCouponGift[idx].values[i], 'value1', val)
    },
    filterRate (idx, i) {
      let val = this.formValidate.addCouponGift[idx].values[i].value2
      if (this.activityTypeId === '8') {
        if (val !== '' && val.substring(0, 1) === '.') {
          val = ''
        }
        val = val.replace(/^0*(0\.|[1-9])/, '$1')
        val = val.replace(/[^\d.]/g, '')
        val = val.replace(/\.{2,}/g, '.')
        val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
        val = val.replace(/^(-)*(\d+)\.(\d).*$/, '$1$2.$3')
        if (val >= 10) {
          val = val.substring(0, val.length - 1)
        }
        if (val.indexOf('.') === 2) {
          val = val.substring(0, 2)
        }
        if (val.length === 2 && val === '00') {
          val = '0'
        }
      } else {
        val = val.replace(/[^\d]/g, '').replace(/^0{1,}/g, '')
      }
      this.$set(this.formValidate.addCouponGift[idx].values[i], 'value2', val)
    },
    rateBlur (idx, i) {
      let val = this.formValidate.addCouponGift[idx].values[i].value2
      if (this.activityTypeId === '8') {
        if (val > 10) {
          val = val.substring(0, val.length - 1)
        }
        if (val.indexOf('.') === 1 && val.length < 3) {
          val = val.substring(0, 1)
        }
        if (val === '0' || val === '0.0') {
          val = ''
        }
      } else {
        val = val.replace(/[^\d]/g, '').replace(/^0{1,}/g, '')
      }
      this.$set(this.formValidate.addCouponGift[idx].values[i], 'value2', val)
    },
    changeProduct () {
      if (this.formValidate.addCouponGift.length > 0) {
        this.formValidate.addCouponGift = this.formValidate.addCouponGift.map((ele, i) => {
          let valuesArr = []
          this.formValidate.ableProduct.forEach((item, idx) => {
            let val = {}
            if (this.formValidate.ableProduct.length < ele.values.length) {
              ele.values.forEach((cat, m) => {
                if (item === cat.id) {
                  val = this.activityTypeId === '6' ? { value1: cat.value1, id: item } : { value1: cat.value1, value2: cat.value2, id: item }
                }
              })
            } else {
              if (ele.values[idx]) {
                val = this.activityTypeId === '6' ? { value1: ele.values[idx].value1, id: item } : { value1: ele.values[idx].value1, value2: ele.values[idx].value2, id: item }
              } else {
                val = this.activityTypeId === '6' ? { value1: '', id: item } : { value1: '', value2: '', id: item }
              }
            }
            valuesArr.push(val)
          })
          return this.activityTypeId === '6' ? {
            id: ele.id,
            values: valuesArr,
            couponList: ele.couponList,
            integral: ele.integral
          } : {
            id: ele.id,
            values: valuesArr
          }
        })
      }
    },
    addcoupon (item, idx) {
      this.Dmodal = true
      this.addId = item.id
      this.itemIdx = idx
      this.activityGiftList = item.couponList
    },
    delLevel (item, idx) {
      this.$refs['item' + idx][0].resetFields()
      if (this.activityTypeId === '6') {
        this.formValidate.addCouponGift[idx] = {
          id: '',
          values: [],
          couponList: [],
          integral: ''
        }
      } else {
        this.formValidate.addCouponGift[idx] = {
          id: '',
          values: []
        }
      }
      this.formValidate.addCouponGift.splice(idx, 1)
    },
    addGiftNum () {
      if (this.formValidate.addCouponGift.length < 5) {
        this.formValidate.addRankNum++
        if (this.activityTypeId === '6') {
          this.formValidate.addCouponGift.push({
            id: this.formValidate.addRankNum,
            values: this.formValidate.ableProduct.map(item => {
              return { value1: '', id: item }
            }),
            couponList: [],
            integral: ''
          })
          this.giftValidate.push({
            couponList: { required: true, message: '请选择优惠券', type: 'array' },
            integral: { required: true, message: '请输入赠送积分' },
            values: { required: true, message: '请输入', type: 'array' }
          })
        } else if (this.activityTypeId === '7' || this.activityTypeId === '8') {
          this.formValidate.addCouponGift.push({
            id: this.formValidate.addRankNum,
            values: this.formValidate.ableProduct.map(item => {
              return { value1: '', value2: '', id: item }
            })
          })
          this.giftValidate.push({
            values: { required: true, message: '请输入', type: 'array' }
          })
        }
      } else {
        this.$Message.error('最多可设置5个等级！')
      }
    },
    activityStartChange (time) {
      this.formValidate.activityStart = time
      this.activityEndOptions = {
        disabledDate (date) {
          return date.valueOf() < new Date(time.split(' ')[0]).getTime() - 24 * 3600 * 1000
        }
      }
      // if (new Date(this.formValidate.activityEnd).getTime()) {
      //   this.$refs.formValidate.validateField('activityEnd', valid => {})
      // }
    },
    activityEndChange (time) {
      this.formValidate.activityEnd = time
      this.activityStartOptions = {
        disabledDate (date) {
          return date.valueOf() > new Date(time).getTime()
        }
      }
    },
    handleSubmit () {
      let flag = true
      this.formValidate.addCouponGift.forEach((item, index) => {
        this.$refs['item' + index][0].validate(val => {
          if (!val) {
            flag = false
          }
        })
      })
      this.$refs.formValidate.validate(val => {
        if (val && flag) {
          let params = {
            merchantId: this.merchantId,
            activityBase: {
              merchantId: this.merchantId,
              activityType: this.activityTypeId, // 6满赠 7满减 8折扣
              activityName: this.formValidate.activityName,
              startTime: this.formValidate.activityStart,
              endTime: this.formValidate.activityEnd,
              creatorId: this.userId,
              creatorName: this.userName,
              remark: this.formValidate.activityRemark
            },
            templates: [],
            rules: []
          }
          // if (this.formValidate.sendWechat !== '-1') {
          //   params.templates.push({
          //     templateId: this.formValidate.sendWechat,
          //     templateType: '1'
          //   })
          // }
          if (this.formValidate.sendMessage !== '-1') {
            params.templates.push({
              templateId: this.formValidate.sendMessage,
              templateType: '2'
            })
          }
          if (params.templates.length === 0) {
            delete params.templates
          }
          this.formValidate.ableProduct.forEach((ele, idx) => {
            let baseData = {
              matchRules: {
                shopId: this.formValidate.faceShop,
                channel: this.formValidate.channel,
                memberLevel: this.formValidate.faceMember,
                itemType: 1,
                itemId: [ele]
              },
              processRules: []
            }
            this.formValidate.addCouponGift.forEach((item, i) => {
              let obj = {
                processMethod: this.activityTypeId === '6' ? 1 : 0,
                accumType: 0,
                processTarget: 0,
                accumAmount: item.values[idx].value1
              }
              if (this.activityTypeId === '6') { // 满赠
                obj.giftList = item.couponList.map(v => {
                  return {
                    giftType: v.refType,
                    giftId: v.refId,
                    amount: 1,
                    promotionAmount: v.promotionAmount
                  }
                })
                obj.giftList.push({
                  giftType: 3,
                  amount: item.integral
                })
              } else if (this.activityTypeId === '7') { // 满减
                obj.discountType = 0
                obj.promotionAmount = item.values[idx].value2
              } else if (this.activityTypeId === '8') { // 折扣
                obj.discountType = 1
                obj.promotionAmount = item.values[idx].value2
              }
              baseData.processRules.push(obj)
            })
            params.rules.push(baseData)
          })
          this.addFuc({ ...params })
        }
      })
    },
    handleReset () {
      this.$store.commit('closeTag', this.$route)
      this.$store.commit('setTagNavList', this.$store.state.app.tagNavList.filter(item => !routeEqual(this.$route, item)))
      this.$nextTick(() => {
        this.$router.push({
          name: 'market_freegift_list'
        })
      })
    },
    // 新增
    addFuc (data) {
      if (this.submitLock) {
        return
      }
      this.submitLock = true
      addFreeGift(data).then(res => {
        this.submitLock = false
        if (res.data.status === 200) {
          this.$Message.success('新增成功！')
          this.handleReset()
        } else {
          this.$Message.error(`${res.data.error}`)
        }
      }).catch(err => {
        this.submitLock = false
        this.$Message.error(`${err}`)
      })
    },
    handleSelectCoupon (val) {
      this.formValidate.addCouponGift.forEach(ele => {
        if (this.addId === ele.id) {
          ele.couponList = val
        }
      })
      this.$refs['item' + this.itemIdx][0].validateField('couponList', valid => {})
    },
    // 查询会员等级
    getMemberLevel () {
      getMemberLevelList({
        merchantId: this.$store.state.user.merchantId
      }).then(res => {
        if (res.data.status === 200) {
          this.memberLevelList = res.data.data || []
          if (this.memberLevelList.length > 0) {
            this.memberLevelList = this.memberLevelList.map(item => {
              return { memberLevel: item.memberLevel + '' }
            })
          }
        } else {
          this.$Message.error(`${res.data.error}`)
        }
      })
    }
  },
  mounted () {
    this.activityTypeId = this.$route.params.type
    this.getMemberLevel()
    this.getOrgTree()
    // this.getEnums(1).then(data => {
    //   this.sendWechats = [{ templateName: '无', id: '-1' }].concat(data || [])
    // })
    this.getEnums(2).then(data => {
      this.sendMessages = [{ templateName: '无', id: '-1' }].concat(data || [])
    })
  }
}
</script>

<style lang='less'>
  #market_freegift_create{
    .del-level{
      position: absolute;
      right: 20px;
      top: 20px;
    }
    .add-level{
      position: relative;
      border: 1px solid #E9E9E9;
      border-radius: 3px;
      margin-bottom: 24px;
      padding-top: 20px;
    }
    .level-special1{
      .ivu-form-item-error-tip {
        left: 145px;
      }
    }
    .level-special2{
      .ivu-form-item-error-tip {
        left: 68px;
      }
    }
    .chunk{
      display: block;
    }
    .treeselect_box {
      display: inline-block;
      span {
        line-height: 18px;
        margin-right: 8px;
      }
    }
    .vue-treeselect__control,
    .vue-treeselect__input-container {
      height: 30px !important;
    }
    .vue-treeselect--has-value .vue-treeselect__multi-value {
      margin-bottom: -4px;
    }
    .vue-treeselect__multi-value-item-container {
      padding-top: 3px;
    }
  }
</style>
